#include "Login.h"
#include "Set.h"
#include "ui_Set.h"

#include <QMessageBox>
#include "mainwindow.h"
Set::Set(QWidget *parent) :
    MyDialog(parent),
    ui(new Ui::Set)
{
    ui->setupUi(this);
    dialogName=setDialog;
    this->ui->ipEdit->setText(Login::myTCPClient->getIp());
    this->ui->portEdit->setText(QString::number(Login::myTCPClient->getPort()));
}

Set::~Set()
{
    delete ui;
}

void Set::on_savePush_clicked()
{
    if(this->ui->ipEdit->text()!=Login::myTCPClient->getIp() || this->ui->portEdit->text()!=QString::number(Login::myTCPClient->getPort()))
    {
        QString str="UPDATE server SET ip='%1',port='%2';";
        str=str.arg(this->ui->ipEdit->text()).arg(this->ui->portEdit->text());
        if(MainWindow::mySqlite->query.exec(str))
        {
            QMessageBox* box=new QMessageBox;
            box->warning(nullptr,"","重要参数被修改，请重新打开");
            QApplication::quit();
        }
    }
}

void Set::siriWork(MyDialog::MyDialogName name, functionFlag flag)
{
    switch (flag) {
    case functionFlag::call_yes:
        emit this->showPatient_signal(MyDialog::showPatientInfor);
        break;
    case functionFlag::call_cancel:
        if(name!=this->dialogName)
            this->showPatient_signal("");
        else if(name==this->dialogName)
        {
            this->showPatient_signal("");
            emit this->siriWork_signal(name,flag);
        }
        break;
    default:
        emit this->siriWork_signal(name,flag);
    }
}
